<?php
$this->beginWidget('bootstrap.widgets.TbBox', array(
	'title' => array(
		'用户列表' => array('user/index'),
		$model->isNewRecord ? '添加用户' : '修改用户 [' . $model->username . ']',
	),
	'headerIcon' => 'icon-user',
));

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'enableClientValidation' => true,
));	/* @var $form TbActiveForm */

// alert tips
$this->widget('bootstrap.widgets.TbAlert', array(
	'block' => true, // display a larger alert block?
	'fade' => true, // use transitions?
	'closeText' => '×', // close link text - if set to false, no close link is displayed
	'alerts' => array('success', 'error'),
));
?>
<div class="row-fluid">
	<div class="span6"><?php echo $form->textFieldRow($model, 'username', array('class' => 'span10', 'readonly' => $model->getIsAdmin())); ?></div>
	<div class="span6"><?php echo $form->textFieldRow($model, 'email', array('class' => 'span10')); ?></div>
</div>
<div class="row-fluid">
	<div class="span6"><?php echo $form->passwordFieldRow($model, 'password', array('class' => 'span10')); ?></div>	
</div>
<?php if (!$model->getIsAdmin()): ?>
<?php foreach ($projects as $project): ?>
	<?php $this->beginClip($project . ' ' . CHtml::tag('i', array('class' => $model->hasAccess($project) ? 'icon-ok-circle' : 'icon-ban-circle'), '')); ?>
	<div class="user-access">
		<?php foreach ($accessList as $route => $label): ?>
		<label class="checkbox">
			<?php echo CHtml::checkBox('accessItem[' . $project . '][' . $route . ']', $model->hasAccess($project, $route)); ?>
			<?php echo $label; ?>
		</label>
		<?php endforeach; ?>
		<label class="checkbox text-error">
			<input type="checkbox" class="check-all" />全选/取消
		</label>
	</div>
	<?php $this->endClip(); ?>
<?php endforeach; ?>
<?php
$this->widget('zii.widgets.jui.CJuiAccordion', array(
	'panels' => $this->clips,
	// additional javascript options for the accordion plugin
	'options' => array(
		'animated' => 'bounceslide',
	),
	'htmlOptions' => array(
		'class' => 'row-bottom',
	),
));
?>
<?php endif; ?>
<div class="row-fluid row-bottom">
	<div class="span6">
		<?php
		$this->widget('bootstrap.widgets.TbButton', array(
			'buttonType' => 'submit',
			'type' => 'primary',
			'label' => $model->isNewRecord ? '添加' : '更新',
		));
		?>
	</div>
</div>
<?php
$this->endWidget();
$this->endWidget();
?>
<script type="text/javascript" pos="ready">
$('input.check-all').click(function(){
	var $pp = $(this).parent().parent();
	$pp.find('input:checkbox').attr('checked', this.checked);
});
$('input:checkbox').click(function(){
	var $pp = $(this).parent().parent();
	var $h3 = $pp.parent().prev();
	$h3.find('i').attr('class', $pp.find('input:checked').size() === 0 ? 'icon-ban-circle' : 'icon-ok-circle');
});
</script>
